<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>首页</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/allApp.css" />
		<style>
			.mui-content {
				/*height:100vh;*/
				width: 100%;
			}
			
			#img1 {
				/*height:40vh;*/
				width: 100%;
			}
			/*九宫格样式*/
			
			.home_icon {
				width: 100%;
			}
			
			.mui-icon {
				width: 100%;
				padding: 0 26%;
			}
			
			.mui-grid-view.mui-grid-9 {
				background: #fff;
				padding: 10px 0;
			}
			
			.mui-grid-view.mui-grid-9 .mui-table-view-cell {
				border: none;
				padding: 5px 15px;
			}
			/*图标样式*/
			
			#lineChart {
				width: 100%;
				height: 340px;
				background: #fff;
				padding: 16px 15px;
				margin-top: 10px;
			}
		</style>
	</head>

	<body>
		<div class="mui-content">
			<img id="img1" src="img/shouyetop.png" />
			<ul class="mui-table-view mui-grid-view mui-grid-9">
				<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="network">
					<a href="#">
						<span class="mui-icon ">
              <img src="img/shouye1.png" class="home_icon"/>
            </span>
						<div class="mui-media-body">电子开票</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="jiankong">
					<a href="#">
						<span class="mui-icon ">
		            	<img src="img/shouye4.png" class="home_icon"/>
		            	
		            </span>
						<div class="mui-media-body">巡回检查</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="regular">
					<a href="#">
						<span class="mui-icon ">
							<img src="img/shouye2.png" class="home_icon"/>
						</span>
						<div class="mui-media-body">定检风机</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="anquanyun">
					<a href="#">
						<span class="mui-icon ">
		            	<img src="img/shouye3.png" class="home_icon"/>
		            	
		            </span>
						<div class="mui-media-body">安全云</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="zhenduan">
					<a href="#">
						<span class="mui-icon ">
		            	<img src="img/shouye5.png" class="home_icon"/>
		            	
		            </span>
						<div class="mui-media-body">远程诊断</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-4" id="more">
					<a href="#">
						<span class="mui-icon ">
		            	<img src="img/shouye7.png" class="home_icon"/>
		            	
		            </span>
						<div class="mui-media-body">一机一档</div>
					</a>
				</li>
			</ul>
			<div class="chart" id="lineChart"></div>
		</div>
	</body>
	<script src="../../js/mui.min.js"></script>
	<script type="text/javascript" src="js/echarts.js"></script>
	<script type="text/javascript" src="../../js/jquery-3.2.1.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>

	<script src="../../js/mkeyplus.base.js"></script>
	<script>
		var network;
		mui.init()
		mui.plusReady(function() {
			var self = plus.webview.currentWebview();
			network = self.network;
			
			// clickTo('shigong');
			clickTo('anquanyun');
//			clickTo('jiankong');
			clickTo('zhenduan');
			// clickTo('more');
			home();
			
			$('#network').on('tap', function() {
        
				mui.openWindow({
					url: '../notice/network.html',
					id: 'network.html',
					extras: {
						network: network
					}
				})
			});
			$('#jiankong').on('tap', function() {
				mui.openWindow({
					url: '../jiankong/jiankong.html',
					id: 'jiankong.html',
					extras: {
//						network: network
					}
				})
			});
			$('#regular').on('tap', function() {
				mui.openWindow({
					url: '../regularCheck/index.html',
					id: '../regularCheck/index.html',
					extras: {}
				})
			});
      $('#more').on('tap', function() {
        //先获取token再获取数据
        
        if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
          mui.openWindow({
            url: '../ddms/home.html',
            id: '../ddms/home.html',
            extras: {}
          })
          return;
        }
        console.log(Config.ddmsUrl)
        console.log(localStorage.getItem('username'))
        mui.baseApp.httpRequst('/api/v2/users/getToken', {
        	employeeNo: localStorage.getItem('username'),
          type:2
        }, function(data) {
          console.log('11111'+JSON.stringify(data))
            if(data.status==200){
              localStorage.setItem("token",data.data)
              mui.openWindow({
              		  url: '../ddms/home.html',
              		  id: '../ddms/home.html',
              		  extras: {}
              		})
            }
          }, function() {
          plus.nativeUI.closeWaiting();
          console.log("登录失败");
        });
        // mui.ajax(Config.ddmsUrl+'/auth/login',{
        // 	data:{
        // 		username:'admin',
        // 		password:'Cgnne@123'
        // 	},
        // 	dataType:'json',//服务器返回json格式数据
        // 	type:'post',//HTTP请求类型
        // 	timeout:10000,//超时时间设置为10秒；
        // 	headers:{'Content-Type':'application/json'},	              
        // 	success:function(data){
        //     console.log('11111'+ JSON.stringify(data))
        //     localStorage.setItem("token",data.token);
        // 		mui.openWindow({
        // 		  url: '../ddms/home.html',
        // 		  id: '../ddms/home.html',
        // 		  extras: {}
        // 		})
        // 	},
        // 	error:function(xhr,type,errorThrown){
        // 		//异常处理；
        // 		console.log(type);
        // 	}
        // });
        
				
			});
			
			//获取风场信息
			getorg();
		});
		//获取风场信息
		function getorg() {
			console.log("userid====="+localStorage.getItem('userid'));
			mui.baseApp.httpRequst("/api/v2/users/findUserOrg", {userid: localStorage.getItem('userid')}, 
			function(data) {
				console.log("获取风场信息成功" + JSON.stringify(data));
				if(data.status == 200) {
					console.log("获取风场信息成功");
					localStorage.setItem("orglist",JSON.stringify(data.data));
					localStorage.setItem("org_code",JSON.stringify(data.data[0].org_code));
					localStorage.setItem("windName",JSON.stringify(data.data[0].desc));
					console.log('org_code++++'+localStorage.getItem('org_code'));
				}else if(data.status == "500") {
					console.log("获取风场信息失败");
				}
			}, function() {
				console.log("获取风机失败");
			})
		}

		function clickTo(id) {
			$('#' + id).on('tap', function() {
				mui.toast('该功能暂未开发');
			});
		}
		// 基于准备好的dom，初始化echarts实例
		var myChart = echarts.init(document.getElementById('lineChart'));
//		var myChart = echarts.init(('lineChart'));
		var options = {
			title: {
				text: '风功率预测',
				subtext: '' //纯属虚构
			},
			tooltip: {
				
			},
			legend: {
				data: ['发电量', '风速']
			},
			toolbox: {},
			xAxis: {
				type: 'category',
//				boundaryGap: false,
				data: ['1', '2', '3', '4', '5', '6', '7']
			},
			yAxis: {
				type: 'value',
				axisLabel: {
					formatter: '{value}'
				}
			},
			series: [{
					name: '发电量',
					type: 'line',
					data: [30, 25, 11, 16, 14, 15, 31],
					symbolSize: 10,
					markPoint: {
						data: [{
								type: 'max',
								name: '最大值'
							},
							{
								type: 'min',
								name: '最小值'
							}
						]
					},
					markLine: {
						data: [{
							type: 'average',
							name: '平均值'
						}]
					}
				},
				{
					name: '风速',
					type: 'line',
					data: [2, 5, 3, 1, 4, 6, 7],
					symbolSize: 10,
					markPoint: {
						data: [{
							name: '周最低',
							value: 5,
							xAxis: 35,
							yAxis: 35
						}]
					},
					markLine: {
						data: [{
								type: 'average',
								name: '平均值'
							},
							[{
								symbol: 'none',
								x: '90%',
								yAxis: 'max'
							}, {
								symbol: 'circle',
								label: {
									normal: {
										position: 'start',
										formatter: '最大值'
									}
								},
								type: 'max',
								name: '最高点'
							}]
						]
					}
				}
			],
			backgroundColor: {
				color: {
					type: 'linear',
					x: 1,
					y: 2,
					x2: 4,
					y2: 1,
					colorStops: [{
						offset: 1,
						color: 'red' // 0% 处的颜色
					}, {
						offset: 1,
						color: 'yellow' // 100% 处的颜色
					}],
					globalCoord: false // 缺省为 false
				}
			}
		};
		myChart.setOption(options);
//		mycharts.hideLoading();
		//获取待办数据
		function home() {
			console.log('userid====' + localStorage.getItem('userid'));
			mui.baseApp.httpRequst('/api/v2/users/home', {
				userid: localStorage.getItem('userid'),
				name: localStorage.getItem('username'),
				unit: localStorage.getItem('unit')
			}, function(data) {
				if(data.status == "200") {
					console.log("获取首页信息成功!");
					var data = data.data;
					console.log(JSON.stringify(data));
					console.log("待办通知条数=====" + data.qmcount);
					console.log("待办工单条数=====" + data.aufcount);
					console.log("待办工作票条数=====" + data.qzpcount);
					localStorage.setItem('qmcount', data.qmcount);
					localStorage.setItem('aufcount', data.aufcount);
					localStorage.setItem('qzpcount', data.qzpcount);
				} else if(data.status == "500") {
					console.log("获取首页信息失败");
				}
			}, function() {
				console.log("获取首页信息失败");
				//					mui.toast("获取首页信息失败！！！");
			});
			//				plus.nativeUI.closeWaiting();
		}
		
	</script>

</html>